package com.crr.mall.product.app;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.crr.mall.common.bean.ResultBean;
import com.crr.mall.common.utils.BaseController;
import com.crr.mall.product.util.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.crr.mall.product.entity.CategoryEntity;
import com.crr.mall.product.service.CategoryService;


/**
 * 商品三级分类
 *
 * @author chenrenren
 * @email chenrenren@gmail.com
 * @date 2024-11-22 17:42:37
 */
@RestController
@RequestMapping("/product/category")
public class CategoryController extends BaseController {
    @Autowired
    private CategoryService categoryService;

    /**
     * 列表
     */
    @GetMapping("/list/tree")
    // @RequiresPermissions("product:category:list")
    public ResultBean list() {
        List<Map> list = categoryService.queryTree(0);

        return success("分类列表", list);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{catId}")
    // @RequiresPermissions("product:category:info")
    public ResultBean info(@PathVariable("catId") Long catId) {
        CategoryEntity category = categoryService.getById(catId);
        return success("category分类", category);
    }

    /**
     * 保存
     */
    @PutMapping("/save")
    // @RequiresPermissions("product:category:save")
    public ResultBean save(@RequestBody CategoryEntity category) {
        boolean save = categoryService.save(category);
        return save ? saveResult(1) : saveResult(0);
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    // @RequiresPermissions("product:category:update")
    public ResultBean update(@RequestBody CategoryEntity category) {
        boolean b = categoryService.updateById(category);
        return b ? updateResult(1) : updateResult(0);
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    // @RequiresPermissions("product:category:delete")
    public ResultBean delete(@RequestBody Long[] catIds) {
        int i = categoryService.removeMenusByIds(Arrays.asList(catIds));
        return deleteResult(i);
    }

}
